package com.sf.sms.user.entity;

import com.sf.sms.utils.IdEntity;
import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.*;

/**
 * Created by 80002004 on 2016/8/29.
 */
public class User extends IdEntity implements Serializable {

    /**用户名*/
    private String userName;
    /**密码*/
    private String passWord;
    /**用户代码*/
    private String userCode;
    /**是否有效 0无效，1有效*/
    private String isValid;
    /**创建日期*/
    private Date createTime;
    /**修改日期*/
    private Date modifyTime;
    /**用户角色*/
    private List<Role> roles = new ArrayList<Role>();
    /**用户资源*/
    private List<Resources> resources = new ArrayList<Resources>();

    /*public User(String userName, String passWord, String userCode, String isValid, Date createTime, Date modifyTime) {
        this.userName = userName;
        this.passWord = passWord;
        this.userCode = userCode;
        this.isValid = isValid;
        this.createTime = createTime;
        this.modifyTime = modifyTime;
    }*/

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public String getIsValid() {
        return isValid;
    }

    public void setIsValid(String isValid) {
        this.isValid = isValid;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Set<String> getRoles() {
        if(!CollectionUtils.isEmpty(roles)) {
            Set<String> roleSet = new HashSet<String>();
            Iterator<Role> its = roles.iterator();
            while(its.hasNext()) {
                roleSet.add(its.next().getRoleCode());
            }
            return roleSet;
        }
        return null;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public Set<String> getResources() {
        if(!CollectionUtils.isEmpty(resources)) {
            Set<String> resourceSet = new HashSet<String>();
            Iterator<Resources> its = resources.iterator();
            while(its.hasNext()) {
                resourceSet.add(its.next().getResCode());
            }
            return resourceSet;
        }
        return null;
    }

    public void setResources(List<Resources> resources) {
        this.resources = resources;
    }
}
